import 'dart:io';
import 'package:flutter_juwo/provider/CheckAccountModel.dart';
import 'package:flutter_juwo/provider/TaskIndex.dart';
import 'package:flutter_juwo/provider/TaskTimerBottomModel.dart';
import 'package:flutter_juwo/provider/TaskTimerModel.dart';
import 'package:flutter_juwo/provider/UserInforModel.dart';
import 'package:flutter_juwo/ui/utils/sp_util.dart';
import 'package:flutter_juwo/ui/utils/utils.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:jpush_flutter/jpush_flutter.dart';

import 'common/common_index.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'provider/index_provider.dart';
import 'package:flutter_juwo/routers/application.dart';
import 'package:flutter_juwo/routers/routes.dart';
import 'package:flutter_juwo/ui/pages/bottom_bar.dart';
import 'package:provider/provider.dart';

import 'package:flutter/rendering.dart';

import 'ui/custom/NoSplashFactory.dart';
//import 'package:amap_location/amap_location.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  //AMapLocationClient.setApiKey("2eef49feb9f03992870bd7d77c35af81");
  await SpUtil.getInstance();
  final goodsDetailsDistanceModel = GoodsDetailsDistanceModel();
  final userModel = UserModel();
  final userPhoneModel = UserPhoneModel();
  final userInforModel = UserInforModel();
  final taskTimerModel = TaskTimerModel();
  final taskTimerBottmModel = TaskTimerBottomModel();
  final taskIndexModel = TaskIndexModel();
  final checkAccount = CheckAccountModel();

  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
  runApp(new MultiProvider(
    providers: [
      ChangeNotifierProvider.value(value: goodsDetailsDistanceModel),
      ChangeNotifierProvider.value(value: userPhoneModel),
      ChangeNotifierProvider.value(value: userModel),
      ChangeNotifierProvider.value(value: userInforModel),
      ChangeNotifierProvider.value(value: taskTimerModel),
      ChangeNotifierProvider.value(value: taskTimerBottmModel),
      ChangeNotifierProvider.value(value: taskIndexModel),
      ChangeNotifierProvider.value(value: checkAccount),
    ],
    child: MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  final JPush jpush = new JPush();

  MyApp() {
    final router = new Router();
    Routes.configureRoutes(router);
    Application.router = router;
  }

  @override
  Widget build(BuildContext context) {

    if (Platform.isAndroid) {
      ///设置状态栏透明
      SystemUiOverlayStyle systemUiOverlayStyle =
          SystemUiOverlayStyle(statusBarColor: Colors.transparent);
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }

    return MaterialApp(
        title: '巨沃推手',
        theme: Theme.of(context).copyWith(
            highlightColor: Colors.transparent,
            splashFactory: const NoSplashFactory(),
            //禁掉水波纹效果
            primaryColor: Colours.appBaseColor,
            backgroundColor: Colours.appBgColor,
            accentColor: Colours.white,
            textTheme: TextTheme(
              body1: TextStyle(color: Colours.appTvColor, fontSize: 16.0),
            ),
            iconTheme: IconThemeData(color: Colours.appBaseColor, size: 35.0)),
        home: BottomNavigationWidget(),
        onGenerateRoute: Application.router.generator,
        localizationsDelegates: [
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
        ],
        supportedLocales: const [
          Locale('zh', 'CH'),
          Locale('en', 'US')
        ]);
  }
}
